package com.ven.simple.autoci

import android.os.Bundle
import android.widget.Button
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import com.blankj.utilcode.util.AppUtils
import com.ven.assists.AssistsCore
import com.ven.assists.service.AssistsService
import com.ven.assists.service.AssistsServiceListener
import com.ven.assists.utils.CoroutineWrapper
import kotlinx.coroutines.delay

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        AssistsService.listeners.add(object : AssistsServiceListener {
            override fun onServiceConnected(service: AssistsService) {
                CoroutineWrapper.launch {
                    while (true) {
                        AssistsCore.back()
                        delay(500)
                        if (AssistsCore.getPackageName() == AppUtils.getAppPackageName()) {
                            break
                        }
                    }

                }
            }
        })
        findViewById<Button>(R.id.btn_test).setOnClickListener {

            if (AssistsCore.isAccessibilityServiceEnabled()) {
                Overlay.show()
            } else {
                AssistsCore.openAccessibilitySetting()
            }

        }
    }

    override fun onResume() {
        super.onResume()
        if (AssistsCore.isAccessibilityServiceEnabled()) {
            Overlay.show()
        }

    }
}